import time

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

def write_local_file(filename,text):
    with open(filename,"w",encoding="utf-8") as file:
        file.write(text)
        file.close()

def test_web():
    url = "https://www.jd.com/"

    # binary = FirefoxBinary(r"C:\Program Files\Mozilla Firefox\firefox.exe")
    # driver = webdriver.Firefox(firefox_binary=binary)

    driver = webdriver.Firefox()
    driver.get(url)

    # 驱动模拟网页的搜索过程
    driver.find_element_by_id("key").send_keys("手机")
    driver.find_element_by_class_name("button").click()

    # 存到本地
    # response = driver.page_source
    # write_local_file("selen_jd.html",response)

    time.sleep(10)
    driver.quit()

test_web()



